package br.panthro.utils.content
{
	import br.panthro.ui.Background.Background;
	import br.panthro.ui.Background.BackgroundEvent;
	import br.panthro.ui.navigation.Menu;
	import br.panthro.utils.stage.StageEvent;
	import br.panthro.utils.stage.StageUtil;
	
	import caurina.transitions.Tweener;
	
	import flash.display.Sprite;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	
	public class ContentManager extends Sprite
	{
		private var _stageUtil:StageUtil = new StageUtil();
		private var _content:Object;
		private var _backgroundManager:Background = new Background();
		private var _background:Sprite;
		private var _menu:Menu;
		
		public function init(content:Object):void
		{
			_content = content;
			
			if(_content.background)
			{
				_backgroundManager.setProperties(_content.background);
				_backgroundManager.addEventListener(BackgroundEvent.READY, backgroundReady);
				
			}
			_stageUtil.stage.addEventListener(StageEvent.RESIZE, stageResizeHandler);
		}
		
		private function backgroundReady(event:BackgroundEvent):void
		{
			_background = _backgroundManager.content;
			_background.alpha = 0;
			addChild(_background);
			Tweener.addTween(_background, {alpha:1, time:.5, delay:0, transition:"linear", onComplete:createNavigation});
		}
		
		private function stageResizeHandler(event:StageEvent):void
		{
			trace(_stageUtil.stage.stageWidth);
		}
		
		private function createNavigation():void
		{
			_menu = new Menu();
			
			_menu.setup(_content.pages);
		}
	}
}